home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Util / F-Fi / Find Entity v1.0b.cpt / findEntity.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-31  |  19.4 KB  |  685 lines  |  [TEXT/KAHL]

  1. #ifdef COMMENT
  2.  
  3.     |    testATP.c
  4.     |
  5.     |    This program scans the AppleTalk network for any specified AppleTalk servers
  6.     |    and displays them in a list. This is the Beta-test for a project which
  7.     |    I'm working on currently. I though it might be of interest to those
  8.     |    exploring the preferred AppleTalk interface, and entity structures.
  9.     |
  10.     |    <c>1991 Mike Carter, MCDesign. You may use portions of this code if you like.
  11.     |    Bug reports and any (and all) comments are welcome! You can reach me via
  12.     |    E-Mail at CompuServe 76114,321.
  13.     |
  14.     |    'FindEntity' is an MCDesign original. All rights reserved.
  15.     |
  16.     |    (Be sure to include AppleTalk, nAppleTalk, MacTraps & ANSI in your project)
  17.  
  18. #endif
  19.  
  20. #define SEARCH                1                /* Dialog items - main DLOG 129 */
  21. #define LIST                2
  22. #define NUMFOUND            3
  23. #define DONE                4
  24. #define LINE                6
  25. #define ICON                7
  26. #define MSG                    8
  27. #define CHANGE                11
  28. #define ENTITY                12
  29. #define HELP                13
  30.  
  31. #define LOOKING                1                /* Message strings */
  32. #define LOOKUPERR            2
  33. #define EXTRACTERR            3
  34. #define NO_DEVICES            4
  35. #define ALL_DONE            5
  36.  
  37. #define OK                    1                /* From set options DLOG 130 */
  38. #define CANCEL                2
  39. #define OBJ_ITEM            3
  40. #define TYPE_ITEM            4
  41. #define ZONE_ITEM            5
  42.  
  43. #define BASE_RES            128
  44. #define NIL_POINTER            0L
  45. #define    WNE_TRAP_NUM        0x60
  46. #define    UNIMPL_TRAP_NUM        0x9F
  47.  
  48. #include <nAppleTalk.h>
  49. #include <ListMgr.h>
  50. #include <string.h>
  51.  
  52. typedef struct {            /* this structure holds data on all found entities */
  53.     Str32    eName;            /* the entity's name */
  54.     Str32    eType;            /* the entity's type */
  55.     int        eNode;            /* the Node -- in decimal form */
  56.     int        eSocket;        /* the socket -- in decimal form */
  57. } response;
  58.  
  59. void DrawTheLine( DialogPtr );                    /* Draws a dotted line on a userItem */
  60. void DrawButton( DialogPtr );                    /* outlines default button */
  61. void DoAlert( short );                            /* Changes message area in DLOG */
  62. int findPrinters( response *, short * );            /* does all the ATP stuff */
  63. void doMyUpdate( Boolean );                        /* updates DLOG */
  64. void Show_help( short, short, short, StringPtr, StringPtr );
  65.  
  66.  
  67. Str32            theObj = "\p=";                    /* Default settings for entity: */
  68. Str32            theType = "\pLaserWriter";        /* Any LaserWriter... */
  69. Str32            theZone = "\p*";                /* in our zone. */
  70. DialogPtr        mainDlog, changeDlog;
  71. GrafPtr            oldPort;
  72. short            maxToGet = 25;                    /* max number to find */
  73. short            numFound = 0;                    /* number found in search */
  74.  
  75. ListHandle        theListH;
  76. short            totalCells = 0;                    /* keeps track of the number of cells in list */
  77. Boolean            gDone = false;
  78. Boolean            gWNElmplemented;
  79. EventRecord        gTheEvent;
  80. Ptr                theBuff, ePtr;                    /* NBP receive buffer; entity pointer */
  81. int                buffSize;                        /* size of buffer */
  82. CursHandle        WatchCursor;
  83. Str255    brag = "\pFindEntity <c>1991 MCDesign. Written by Mike Carter (76114,321) in Think C";
  84. response        theResp[25];                    /* See above */
  85.  
  86.  
  87. /******************************* main **********************************/
  88. main()
  89. {
  90.     MaxApplZone();                        /* get some ROOM!!!! */
  91.     InitMac();                            /* initialize Mac Managers */
  92.     
  93.     /* Allocate our main memory-gobbling structures first so        */
  94.     /* they end up at the bottom of our heap, causing much less        */
  95.     /* heap fragmentation. I call this semi-dynamic allocation!        */
  96.     
  97.     buffSize = (sizeof( EntityName ) + 4) * maxToGet;
  98.  
  99.     theBuff = NewPtrClear( buffSize );
  100.     if( theBuff == 0L ) 
  101.         ExitToShell();                    /* No memory!! */
  102.     
  103.     ePtr = NewPtrClear( 100 );            /* size for NBPSetEntity */
  104.     if( ePtr == 0L ) 
  105.         ExitToShell();                    /* no memory!! */
  106.     
  107.     SetUpDlog();                        /* load and show our main dialog */
  108.     
  109.     LoopTheLoop();                        /* main event loop */
  110.     
  111.     /* clean-up routines */
  112.     LDispose( theListH );                /* Can't say whether or not these  */
  113.     DisposPtr( ePtr );                    /* are _really_ necessary, seeing  */
  114.     DisposPtr( theBuff );                /* that quitting the app. releases */
  115.     DisposDialog( mainDlog );            /* it's memory anyway--but what the */
  116.     HPurge((Handle)WatchCursor);        /* heck! can't hurt!!                */
  117.     
  118.     SetPort( oldPort );                    /* Set the GrafPort back the way we found it */
  119.         
  120.     ExitToShell();                        /* ta-ta for now */
  121. }
  122.  
  123. /*********************** InitMac **************************/
  124. InitMac()
  125. {
  126.     InitGraf( &thePort );                /* Initialize the Mac Managers */
  127.     InitFonts();
  128.     FlushEvents( everyEvent, 0 );
  129.     InitWindows();
  130.     InitMenus();
  131.     TEInit();
  132.     InitDialogs( 0L );
  133.     InitCursor();
  134.     
  135.     WatchCursor=GetCursor( watchCursor );    /* standard wait cursor */
  136.     HNoPurge((Handle)WatchCursor);            /* keep it around a while */
  137. }
  138.  
  139. /******************** SetUpDlog *****************************/
  140. SetUpDlog()
  141. {
  142.     int            type = 0, hit = 0;
  143.     Rect        box;
  144.     Handle        itemH;
  145.     
  146.     mainDlog = GetNewDialog( BASE_RES + 1, 0L, -1L );    /* Get our main Dialog */
  147.     if( mainDlog == 0L )
  148.         ExitToShell();
  149.     
  150.     GetPort( &oldPort );                /* Let's be port-friendly */
  151.     SetPort( mainDlog );
  152.     
  153.     SetUpList();                        /* define the list which shows the printer names */
  154.     
  155.     ShowWindow( mainDlog );                /* become visual reality */
  156.     DrawDialog( mainDlog );                /* draw the guts */
  157.     
  158.     doMyUpdate( false );                /* draw outlines--but don't update list-it's non-extant */
  159. }
  160.  
  161.  
  162. /************************ SetUpList ********************************/
  163. SetUpList()
  164. {
  165.     int        type, i;
  166.     Rect    box, dataBounds, rView;
  167.     Point    cSize;
  168.     Handle    itemH;
  169.     Cell    theCell;
  170.     
  171.     GetDItem( mainDlog, LIST, &type, &itemH, &box );
  172.     
  173.     rView = box;                        /* Get rect size from our DITL user item */
  174.     rView.left+=1;                        /* leave room for framerect */
  175.     rView.right-=16;                    /* room for scroll bar and framerect */
  176.     rView.bottom -= 1;                    /* room for framerect */
  177.     
  178.     cSize.h = rView.right - rView.left;                /* set cell size */
  179.     cSize.v = (rView.bottom - rView.top) / 6;        /* show 6 cells at a time */
  180.     
  181.     SetRect(&dataBounds,0,0,1,0);        /* one column, no cells - yet */
  182.     
  183.     theListH = LNew(&rView, &dataBounds, cSize, 0L, mainDlog, true, false, false, true);
  184.     (**theListH).selFlags = lOnlyOne+lNoDisjoint+lNoExtend+lNoNilHilite;
  185.     
  186.     LActivate( false, theListH );         /* turn it off initially */
  187.     
  188. }
  189.  
  190. /**************************** LoopTheLoop ***************************/
  191. LoopTheLoop()
  192. {
  193.     
  194.     /*    Is WaitNextEvent() implemented?  If it is, the address of the
  195.      *    WaitNextEvent() trap will be different than the standard,
  196.      *    "unimplemented" trap...
  197.      */
  198.      
  199.     gWNElmplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap ) !=
  200.                             NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
  201.     
  202.     /*
  203.      *    Don't wait for a mouse click. Retrieve and process events
  204.      *    instead!
  205.      */
  206.  
  207.     while ( gDone == false )
  208.     {
  209.         HandleEvent();
  210.     }
  211. }
  212.     
  213. /*************************** HandleEvent ****************************/
  214. HandleEvent()
  215. {
  216.     int        theItem, type;
  217.     Handle    itemH;
  218.     Rect    box;
  219.     Point    pt;
  220.     int        err = 0;
  221.     long    charCode, fake;
  222.  
  223.     if ( gWNElmplemented )                        /* Use appropriate event routine */
  224.         WaitNextEvent( everyEvent, &gTheEvent, 0L, 0L );
  225.     
  226.     else
  227.     {
  228.         SystemTask();
  229.         GetNextEvent( everyEvent, &gTheEvent );
  230.     }
  231.  
  232.     if (IsDialogEvent( &gTheEvent ) )            /* event happened inside the Dlog?? */
  233.     {
  234.         if ( DialogSelect( &gTheEvent, &mainDlog, &theItem ) )        /* yes it did!! */
  235.         {
  236.             switch( theItem )
  237.             {
  238.                 case SEARCH:                    /* hit the search button */
  239.                     StartHere:                    /* for catching mouseDowns in the next switch */
  240.                     SetCursor(*WatchCursor);
  241.                     
  242.                     err = findPrinters( theResp, &numFound );
  243.                     
  244.                     LActivate( true, theListH );    /* activate the list */
  245.                     InitCursor();                    /* cahnge back to arrow cursor */
  246.                     doMyUpdate( true );
  247.                     
  248.                     if( err != noErr)
  249.                         SysBeep( 30 );
  250.                     break;
  251.                     
  252.                 case DONE:
  253.                     gDone = true;
  254.                     return;
  255.                     
  256.                 case LIST:
  257.                     HandleListClick();
  258.                     break;
  259.                     
  260.                 case ICON:
  261.                     GetDItem( mainDlog, MSG, &type, &itemH, &box );    /* secret brag switch! */
  262.                     SetIText( itemH, &brag );
  263.                     break;
  264.                     
  265.                 case CHANGE:
  266.                     DoChange();
  267.                     doMyUpdate( true );
  268.                     break;
  269.                     
  270.                 case HELP:
  271.                     Show_help( 132, BASE_RES,1000, (StringPtr)"\pFindEntity Help", 
  272.                     (StringPtr)"" );
  273.                     doMyUpdate( true );
  274.                     break;
  275.                     
  276.             } /* switch theItem */
  277.             gTheEvent.what = nullEvent;    /* event handled-reset so next switch doesn't freak out */
  278.             
  279.         } /* DialogSelect */
  280.         
  281.     } /* IsDialogEvent */
  282.     
  283.     
  284.     
  285.     switch ( gTheEvent.what )        /* Okay, event wasn't part of dialog */
  286.     {
  287.         case nullEvent:
  288.             break;
  289.  
  290.         case mouseDown:                /* for drags and any stray DA windows */
  291.             HandleMouseDown();
  292.             break;
  293.         
  294.         case keyDown:
  295.             charCode = BitAnd( gTheEvent.message, charCodeMask);
  296.             if( (charCode == 13) || (charCode == 3) )    /* return or enter key */
  297.             {
  298.                 GetDItem( mainDlog, SEARCH, &type, &itemH, &box );
  299.                 HiliteControl( itemH, 1 );
  300.                 Delay( 10, &fake );                /* do a fake button press hilite */
  301.                 HiliteControl( itemH, 0 );
  302.                 goto StartHere;                    /* same as click in Search button above */
  303.             }
  304.             else if( (charCode == '.') && (gTheEvent.modifiers & cmdKey) )
  305.             {
  306.                 GetDItem( mainDlog, DONE, &type, &itemH, &box );
  307.                 HiliteControl( itemH, 1 );
  308.                 Delay( 10, &fake );                /* do a fake button press hilite */
  309.                 HiliteControl( itemH, 0 );
  310.                 gDone = true;
  311.                 return;
  312.             }
  313.             else if( (charCode == 'c') && (gTheEvent.modifiers & cmdKey) )    /* change button */
  314.             {
  315.                 GetDItem( mainDlog, CHANGE, &type, &itemH, &box );
  316.                 HiliteControl( itemH, 1 );
  317.                 Delay( 10, &fake );
  318.                 HiliteControl( itemH, 0 );
  319.                 DoChange();
  320.                 doMyUpdate( true );
  321.             }
  322.             break;
  323.             
  324.         case updateEvt:
  325.             BeginUpdate( gTheEvent.message );
  326.             DrawDialog( mainDlog );
  327.             doMyUpdate( true );
  328.             EndUpdate( gTheEvent.message );
  329.             break;
  330.     } /* switch gTheEvent */
  331.     
  332. } /* HandleEvent() */
  333.     
  334.     
  335. /**************************** HandleListClick **********************/
  336. HandleListClick()
  337. /* Handles clicks in the list of found entities. */
  338. {
  339.     Point    pt;                            /* location of the click */
  340.     Cell    aCell;                        /* cell where click occurred */
  341.     Rect    box;                        /* GetDItem stuff */
  342.     Handle    itemH;                        /* GetDItem stuff */
  343.     int        type;                        /* GetDItem stuff */
  344.     char    infoString[100];            /* standard C string (The hell w/Pascal!) */
  345.     Str32    name;                        /* crummy pascal string */
  346.     
  347.     pt = gTheEvent.where;                /* get mouseclick from the global eventRecord */
  348.     GlobalToLocal( &pt );                /* the list needs in in local coords */
  349.     LClick( pt, gTheEvent.modifiers, theListH );    /* handle the highlighting */
  350.     *(long *)&aCell = LLastClick(theListH);            /* find the cell last clicked in -- */
  351.                                         /* the fancy footwork is a result of Think C    */
  352.                                         /* returning a long from the call to LLastClick */
  353.                                         /* instead of a Cell--like pascal does.             */
  354.     if( aCell.v+1 <= numFound )            /* Test if user clicked in a valid cell */
  355.     {    
  356.         BlockMove( (Ptr)&theResp[aCell.v+1].eType, &name, *theResp[aCell.v+1].eType+1 );
  357.         PtoCstr( (char *)name );
  358.         sprintf( infoString, "Type: %s, Node: %d, Socket: %d", name,
  359.              (int)theResp[aCell.v+1].eNode, (int)theResp[aCell.v+1].eSocket );
  360.            /** throw together a string--REAL C style!! */
  361.     }
  362.     else
  363.         strcpy( infoString, "???" );    /* user clicked on an empty cell */
  364.         
  365.     CtoPstr( infoString );                /* convert our cool C string to a yucchy pascal string */
  366.     GetDItem( mainDlog, MSG, &type, &itemH, &box );
  367.     SetIText( itemH, infoString );        /* display the message */
  368. }
  369.     
  370. /**************************** HandleMouseDown **********************/
  371. HandleMouseDown()
  372. {
  373.         WindowPtr    whichWindow;
  374.         short int    thePart;
  375.         long        windSize;
  376.         GrafPtr        oldPort;
  377.         Rect        dragRect = screenBits.bounds;
  378.  
  379. /*    First, find out which window the mouse click occurred in.
  380.  *    Then, find out what part of the window the mouse click occurred in.
  381.  */
  382.  
  383.     thePart = FindWindow( gTheEvent.where, &whichWindow );
  384.     switch ( thePart )
  385.     {
  386.         case inSysWindow :                 /*    Probably a desk accessory window... */
  387.             SystemClick( &gTheEvent, whichWindow );
  388.             break;
  389.             
  390.         case inDrag:            /* Drag the window around the screen, limited by dragRect */
  391.             DragWindow( whichWindow, gTheEvent.where, &dragRect);
  392.             DrawDialog( mainDlog );
  393.             doMyUpdate( true );            /* update the screen */
  394.             break;
  395.     }
  396. }
  397.  
  398.  
  399. /***************************** DoChange *****************************/
  400. DoChange()
  401. /* Gets new search information for the next call to findPrinters */
  402. {
  403.     GrafPtr    oldPort;
  404.     Boolean    done = false;
  405.     int        type, itemHit;
  406.     Handle    objH, typeH, zoneH;
  407.     Rect    box;
  408.     Str255    objStr, typeStr, zoneStr;
  409.     
  410.     GetPort( &oldPort );
  411.     changeDlog = GetNewDialog( 130, 0L, -1L );
  412.     SetPort( changeDlog );
  413.  
  414.     GetDItem( changeDlog, OBJ_ITEM, &type, &objH, &box );    /* get handles to editText items */
  415.     GetDItem( changeDlog, TYPE_ITEM, &type, &typeH, &box );
  416.     GetDItem( changeDlog, ZONE_ITEM, &type, &zoneH, &box );
  417.     SetIText( objH, theObj );                /* set editText's to current search strings */
  418.     SetIText( typeH, theType );
  419.     SetIText( zoneH, theZone );
  420.     
  421.     SelIText( changeDlog, OBJ_ITEM, 0, 32767);        /* select first editText's text */
  422.     
  423.     ShowWindow( changeDlog );            /* make sure we're seen */
  424.     DrawDialog( changeDlog );
  425.     
  426.     while( !done )
  427.     {
  428.         ModalDialog( NIL_POINTER, &itemHit );    /* do a modal Dialog */
  429.         switch( itemHit )
  430.         {
  431.             case CANCEL:
  432.                 done = true;
  433.                 break;
  434.             
  435.             case OK:            /* okay, copy new settings to global strings */
  436.                 GetIText( objH, &objStr );
  437.                 if( objStr[0] > 0 )        /* check for empty editText string */
  438.                 {
  439.                     theObj[0] = '\0';
  440.                     BlockMove( objStr, theObj, (Size) objStr[0] + 1 );
  441.                 }
  442.                 
  443.                 GetIText( typeH, &typeStr );
  444.                 if( typeStr[0] > 0 )    /* check for empty editText string */
  445.                 {
  446.                     theType[0] = '\0';
  447.                     BlockMove( typeStr, theType, (Size) typeStr[0] + 1 );
  448.                 }
  449.                     
  450.                 GetIText( zoneH, &zoneStr );
  451.                 if( zoneStr[0] > 0 )    /* check for empty editText string */
  452.                 {
  453.                     theZone[0] = '\0';
  454.                     BlockMove( zoneStr, theZone, (Size) zoneStr[0] + 1 );
  455.                 }
  456.                     
  457.                 done = true;
  458.                 break;
  459.         }
  460.     }
  461.     HideWindow( changeDlog );
  462.     DisposDialog( changeDlog );        /* free up some mem-o-ry */
  463.     SetPort( oldPort );
  464. }
  465.  
  466.  
  467. /************************** findPrinters ****************************/
  468. int findPrinters( response *theResp, short *numFound)
  469. {
  470.     EntityName        aFoundPrinter;            /* holds info for found printers */
  471.     AddrBlock        entityAddr;                /* address for found printers */
  472.     int                type = 0, i = 0;        /* Dlog stuff */
  473.     long            dummy;                    /* Delay() dummy var */
  474.     Handle            itemH;                    /* Dlog stuff */
  475.     Rect            box;                    /* ditto. */
  476.     Str255            look, numStr;            /* a mesage */
  477.     MPPParamBlock    p;                        /* preferred interface paramBlock */
  478.     OSErr            err;                    /* OS err value */
  479.     Cell            theCell;                /* for the Dlog list */
  480.     char            message[100];            /* temp string for composing message */
  481.     
  482.     strcpy( message, "Looking for " );        /* Compose the Looking string */
  483.     strncat( message, (char *)&theType[1], (int)*theType );
  484.     strcat( message, "'s...");
  485.     CtoPstr( message );
  486.     GetDItem( mainDlog, MSG, &type, &itemH, &box );
  487.     SetIText( itemH, &message );
  488.     
  489.     NBPSetEntity( ePtr, theObj, theType, theZone );        /* setup up the entity */
  490.     
  491.     p.ioCompletion = 0L;                /* no completion procedure */
  492.     p.NBPinterval = 2;                    /* interval of two */
  493.     p.NBPcount = 3;                        /* retry three times only */
  494.     p.NBPentityPtr = ePtr;                /* the entity info */
  495.     p.NBPretBuffPtr = theBuff;            /* return buffer */
  496.     p.NBPretBuffSize = buffSize;
  497.     p.NBPmaxToGet = maxToGet;            /* maximum entities to find */
  498.     
  499.     err = PLookupName( &p, false );        /* go lookin' */
  500.     if( err != noErr )
  501.     {
  502.         DoAlert( LOOKUPERR );            /* ATalk error */
  503.         return( -1 );
  504.     }
  505.     
  506.     *numFound = p.NBPnumGotten;            /* copy results */
  507.     
  508.     NumToString( p.NBPnumGotten, &numStr  );                /* change numFound to a */
  509.     GetDItem( mainDlog, NUMFOUND, &type, &itemH, &box );    /* string for display in */
  510.     SetIText( itemH, &numStr );                                /* the dialog box */
  511.     
  512.     if( p.NBPnumGotten <= 0 )            /* none found! */
  513.     {
  514.         if( totalCells < *numFound )
  515.             LAddRow( *numFound - totalCells, totalCells, theListH );
  516.         if( totalCells > *numFound )
  517.             LDelRow( totalCells - *numFound, *numFound, theListH );
  518.         totalCells = *numFound;
  519.         DoAlert( NO_DEVICES );            /* return error code for none found */
  520.         return( -1 );
  521.     }
  522.     
  523.     if( totalCells < *numFound )
  524.         LAddRow( *numFound - totalCells, totalCells, theListH );
  525.     if( totalCells > *numFound )
  526.         LDelRow( totalCells - *numFound, *numFound, theListH );
  527.     
  528.     theCell.h = 0;                        /* we're only using one column, so .h remains 0 */
  529.     
  530.     for( i = 1; i <= p.NBPnumGotten; i++ )                    /* cycle thru and extract */
  531.     {
  532.         err = NBPExtract( theBuff, p.NBPnumGotten, i, &aFoundPrinter, &entityAddr );
  533.         if( err != noErr )
  534.         {
  535.             DoAlert( EXTRACTERR );
  536.             return( -1 );
  537.         }
  538.         
  539.         /* Now move the info of the found printer at index 'i' to the string array   */
  540.         /*  theResp, then copy the name to a cell in our list, finally make sure the */
  541.         /*  cell gets drawn.                                                         */
  542.         BlockMove( (Ptr)&aFoundPrinter.objStr, (Ptr)&theResp->eName[i], *aFoundPrinter.objStr );
  543.         theResp[i].eNode = entityAddr.aNode;
  544.         theResp[i].eSocket = entityAddr.aSocket;
  545.         BlockMove( (Ptr)&aFoundPrinter.typeStr, (Ptr)&theResp[i].eType, 
  546.                             *aFoundPrinter.typeStr+1 ); 
  547.         theCell.v = i - 1;                                    /* go to next cell */
  548.         LSetCell( (Ptr)&aFoundPrinter.objStr[1], aFoundPrinter.objStr[0],
  549.                             theCell, theListH );
  550.         LDraw( theCell, theListH );
  551.     } 
  552.     
  553.     GetDItem( mainDlog, MSG, &type, &itemH, &box );
  554.     SetIText( itemH, "\pAll done!!" );
  555.     
  556.     totalCells = *numFound;            /* update our number 'o cells counter */
  557.     
  558.     return( 0 );        /* all is well */
  559. }
  560.  
  561. /*************************** DoAlert ***************************/
  562. void DoAlert( short index )
  563. {
  564.     int        type;
  565.     Rect    box;
  566.     Handle    itemH;
  567.     Str255    errStr;
  568.     
  569.     GetDItem( mainDlog, MSG, &type, &itemH, &box );            /* statText item */
  570.     GetIndString( &errStr, BASE_RES, index );
  571.     
  572.     SetIText( itemH, &errStr );
  573. }
  574.  
  575. /**************************** doMyUpdate ***************************/
  576. void doMyUpdate( Boolean includeList )
  577. /* Handles all screen updates */
  578. {
  579.     DrawDialog( mainDlog );
  580.     DrawTheLine( mainDlog );
  581.     DrawButton( mainDlog );
  582.     SetCurEntity();
  583.     FrameListRect();
  584.     if( includeList == true )
  585.         LUpdate( (RgnHandle)(**theListH).port->visRgn, theListH );
  586. }
  587.  
  588.  
  589. /**************************** FrameListRect **************************/
  590. FrameListRect()
  591. {
  592.     int        type;
  593.     Rect    box;
  594.     Handle    itemH;
  595.     
  596.     GetDItem( mainDlog, LIST, &type, &itemH, &box );
  597.     box.top -= 1;
  598.     FrameRect( &box );
  599.     
  600.     DisposHandle( itemH );
  601. }
  602.  
  603.  
  604. /************************ SetCurEntity *************************/
  605. SetCurEntity()
  606. /* updates the curent search pattern shown on the main dialog */
  607. {
  608.     int            type, nextLine;
  609.     FontInfo    finfo;
  610.     Handle        itemH;
  611.     Rect        box;
  612.     
  613.     GetDItem( mainDlog, ENTITY, &type, &itemH, &box );
  614.     FillRect( &box, white );
  615.     
  616.     ForeColor( redColor );
  617.     
  618.     TextFont( helvetica );
  619.     GetFontInfo( &finfo );
  620.     nextLine = finfo.ascent + finfo.descent + finfo.leading;
  621.     
  622.     MoveTo( box.left + 8, box.top + nextLine );
  623.     
  624.     DrawString( "\pObject: " );
  625.     DrawString( theObj );
  626.     MoveTo( box.left + 8, box.top + (2 * nextLine) );
  627.     
  628.     DrawString( "\pType: " );
  629.     DrawString( theType );
  630.     MoveTo( box.left + 8, box.top + (3 * nextLine) );
  631.     
  632.     DrawString( "\pZone: " );
  633.     DrawString( theZone );
  634.     
  635. }
  636.  
  637.  
  638. /************************* DrawTheLine *************************/
  639. void DrawTheLine( DialogPtr theDlog )
  640. /* 
  641.     |    This function will, utilizing the Rect defined in the user item
  642.     |    within the rez file, draw a dotted line to seperate the message
  643.     |    line at the bottom of the DLOG from the parts above it.
  644. */
  645. {
  646.     Handle    itemH;
  647.     Rect    box, theRect;
  648.     Point    where, left, right;
  649.     int        type;
  650.     
  651.     GetDItem( theDlog, LINE, &type, &itemH, &box );
  652.     
  653.     PenPat( ltGray );
  654.     PenSize( 1, 1 );
  655.     
  656.     MoveTo( box.left, box.top );
  657.     LineTo( box.right, box.top );
  658.     
  659.     PenNormal();
  660. }
  661.  
  662. /*************************** DrawButton ************************/
  663. void DrawButton( theDialog )
  664. DialogPtr    theDialog;
  665. /* Outlines the default button--actually, I just discovered I can use        */
  666. /* a CDEV resource and CNTL resource in my rez file to do the same thing!! */
  667. /* (it's done that way for the help dialog) */
  668. {
  669.     int        itemType;
  670.     Rect    itemRect;
  671.     Handle    item;
  672.     GrafPtr    oldPort;
  673.     
  674.     GetPort( &oldPort );
  675.     GetDItem( theDialog, SEARCH, &itemType, &item, &itemRect );
  676.     SetPort( theDialog );
  677.     
  678.     PenSize( 3,3 );
  679.     InsetRect( &itemRect, -4, -4 );
  680.     FrameRoundRect( &itemRect, 16, 16 );
  681.     PenNormal();
  682.     
  683.     SetPort( oldPort );
  684. }
  685.